package com.fjzx.androidframe.global.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Preferences 管理类
 *
 * @author xiongyongcong
 */
public class XPreferences {
    private static SharedPreferences mPefs;

    /**
     * 初始化
     *
     * @param context
     * @param prefsName
     */
    public static void init(Context context, String prefsName) {
        mPefs = context.getSharedPreferences(prefsName, Context.MODE_PRIVATE);
    }

    public static String getString(String key, String defValue) {
        return mPefs.getString(key, defValue);
    }

    public static int getInt(String key, int defValue) {
        return mPefs.getInt(key, defValue);
    }

    public static boolean getBoolean(String key, boolean defValue) {
        return mPefs.getBoolean(key, defValue);
    }

    public static long getLong(String key, long defValue) {
        return mPefs.getLong(key, defValue);
    }

    public static float getFloat(String key, float defValue) {
        return mPefs.getFloat(key, defValue);
    }

    public static void putString(String key, String value) {
        mPefs.edit().putString(key, value).apply();
    }

    public static void putInt(String key, int value) {
        mPefs.edit().putInt(key, value).apply();
    }

    public static void putBoolean(String key, boolean value) {
        mPefs.edit().putBoolean(key, value).apply();
    }

    public static void putLong(String key, long value) {
        mPefs.edit().putLong(key, value).apply();
    }

    public static void putFloat(String key, float value) {
        mPefs.edit().putFloat(key, value).apply();
    }

    public static void remove(String key) {
        mPefs.edit().remove(key).apply();
    }
}
